package com.emagic.manage.modules.room.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.emagic.manage.LifeApplication;
import com.emagic.manage.R;
import com.emagic.manage.modules.room.view.AllRoomUser;
import com.emagic.manage.modules.room.view.ClassRoomUser;

import java.util.List;

/**
 * Created by xiatian on 2017/11/13.
 */

public class CommentListAdapter extends BaseMultiItemQuickAdapter<AllRoomUser.RoomUser, BaseViewHolder> {

    private String teacherId, teacherName;

    public CommentListAdapter(List<AllRoomUser.RoomUser> data, String teacherId, String mTeacherName) {
        super(data);
        this.teacherId = teacherId;
        this.teacherName = mTeacherName;
        addItemType(AllRoomUser.RoomUser.MSG, R.layout.msg_view);
        addItemType(AllRoomUser.RoomUser.COM, R.layout.com_view);
        addItemType(AllRoomUser.RoomUser.HSP, R.layout.hsp_view);
    }

    @Override
    protected void convert(BaseViewHolder helper, AllRoomUser.RoomUser item) {
        switch (helper.getItemViewType()) {
            case AllRoomUser.RoomUser.MSG:
                helper.setText(R.id.time_text, item.getTime());
                int state = item.getState();
                TextView msgText = helper.getView(R.id.msg_text);
                String name = "";
                if (!TextUtils.isEmpty(item.getFirstname())) {
                    if (item.getReceiveid().equals(LifeApplication.getInstance().getCurrentUser().getUserid())) {
                        name = "您";
                    } else {
                        name = item.getFirstname();
                    }
                } else {
                    if (item.getReceiveid().equals(teacherId)) {
                        name = teacherName;
                    }
                }
                if (state == ClassRoomUser.PUBLISH_STATE_NONE) {
//                    msgText.setText(name.concat("加入课堂!"));
                    msgText.setText(name.concat("加入家校视频!"));
                } else if (state == ClassRoomUser.PUBLISH_STATE_AUDIOONLY) {
                    msgText.setText(name.concat("已经开始发言，音频已经公开"));
                } else if (state == ClassRoomUser.PUBLISH_STATE_VIDEOONLY) {
                    msgText.setText(name.concat("已经开始发言，视频已经公开"));
                } else if (state == ClassRoomUser.PUBLISH_STATE_BOTH) {
                    msgText.setText(name.concat("已经开始发言，音视频已经公开"));
                } else if (state == -1) {
                    msgText.setText(name.concat("离开课堂!"));
                }
                break;
            case AllRoomUser.RoomUser.COM:
                helper.setText(R.id.time_text, item.getTime())
                        .setText(R.id.name_text, item.getFirstname())
                        .setText(R.id.msg_text, item.getMessage());

                TextView mName = helper.getView(R.id.name_text);
                if (item.getReceiveid().equals(LifeApplication.getInstance().getCurrentUser().getUserid())) {
                    mName.setTextColor(mContext.getResources().getColor(R.color.color_other_2));
                } else {
                    mName.setTextColor(mContext.getResources().getColor(R.color.white));
                }
                break;

            case AllRoomUser.RoomUser.HSP:
                helper.setText(R.id.time_text, item.getTime())
                        .setText(R.id.name_text, item.getFirstname())
                        .setVisible(R.id.agree_layout, item.isShow())
                        .setVisible(R.id.msg_text, !item.isShow())
                        .setText(R.id.msg_text, item.isHeadup() ? "已同意" : "不同意")
                        .addOnClickListener(R.id.disagree)
                        .addOnClickListener(R.id.agree);
                break;
        }

    }
}
